<script lang="ts" setup>
import { computed, reactive, ref } from "vue";
import { ScriptTemplateSelect } from "@/components/business";
import type { FormInstance } from "element-plus";

const props = defineProps({
  dialogVisible: Boolean
});

const emit = defineEmits(["update:dialogVisible", "submit"]);

const visible = computed({
  get() {
    return props.dialogVisible;
  },
  set(val: boolean) {
    emit("update:dialogVisible", val);
  }
});

const form = reactive({
  scriptTemplateId: "",
  name: ""
});

const formRef = ref<FormInstance>();

const submit = () => {
  formRef.value?.validate((valid) => {
    if (valid) {
      emit("submit", form);
      visible.value = false;
    }
  });
};
</script>
<template>
  <el-dialog v-model="visible" title="绑定脚本" width="500">
    <el-form ref="formRef" :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="展示名称">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="选择脚本">
        <script-template-select v-model="form.scriptTemplateId" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="submit"> 确认 </el-button>
      </div>
    </template>
  </el-dialog>
</template>
